package com.ywk.effective._16_composition;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

public class InstrumentedHashSet<E> extends HashSet<E> {
    private int addCount = 0;

    public InstrumentedHashSet() {

    }

    public InstrumentedHashSet(int initCap, float loadFactor) {
        super(initCap);
    }

    @Override
    public boolean add(E e) {
        addCount++;
        return super.add(e);
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        /*addCount += c.size();*/
        return super.addAll(c);
    }


    public int getAddCount() {
        return addCount;
    }
    static class Main{
        public static void main(String[] args) {
            InstrumentedHashSet<String> instrumentedHashSet = new InstrumentedHashSet<>();
            instrumentedHashSet.addAll(Arrays.asList("Snap", "ya", "ho"));
            System.out.println(instrumentedHashSet.getAddCount());
        }
    }
}
